<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Mail extends MY_Controller {
	
	public function __construct(){
		parent::__construct();
	}
	
	public function index(){
		if($this->input->post('submit')){
			$continue = $this->input->get('continue');
			$this->form_validation->set_rules('mail', 'Email', 'trim|required|valid_email');
			if($this->form_validation->run() == TRUE){
				$mail = $this->input->post('mail');
				$check_mail = $this->db->from('mail')->where(array('mail' => $mail))->get()->row_array();
				if(!$check_mail){
					$this->db->insert('mail', array('mail' => $mail, 'created' => gmdate('Y-m-d H:i:s', time() + 7*3600)));
					$this->my_string->js_redirect('Đăng ký mail thành công.', !empty($continue) ? base64_decode($continue) : ITQ_BASE_URL);
				} else{
					$this->my_string->js_redirect('Email này đã được đăng ký.', !empty($continue) ? base64_decode($continue) : ITQ_BASE_URL);
				}
			}
			$this->my_string->js_redirect('Email không định dạng.', !empty($continue) ? base64_decode($continue) : ITQ_BASE_URL);
		}
		
	}

}